package com.nmwlw.demo

import android.content.Context
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Star
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.fristdemo_kotlin.ui.theme.WLWTheme
import com.nmwlw.demo.data.DataSource.IndexOptions
import com.nmwlw.demo.data.enums.NIC700Screen
import com.nmwlw.demo.ui.CommonSetScreen
import com.nmwlw.demo.ui.DemoScreen
import com.nmwlw.demo.ui.SetsScreen
import com.nmwlw.demo.ui.WebViewScreen

@Composable
fun NIC700App(
    navController: NavHostController = rememberNavController()
) {
    //
    val backStackEntry by navController.currentBackStackEntryAsState()
    val currentScreen = NIC700Screen.valueOf(
        backStackEntry?.destination?.route?:NIC700Screen.INDEX_SETS.name
    )

    Scaffold(
        topBar = {
            StatusBar()
        }
    ) { innerPadding ->
        NavHost(
            navController = navController,
            startDestination = NIC700Screen.INDEX_SETS.name,
            modifier = Modifier.padding(innerPadding)
        ) {
            // 主页面
            composable(route = NIC700Screen.INDEX_SETS.name) {
                SetsScreen(
                    itemList = IndexOptions,
                    navController = navController

                )
            }
            //通用设置页面
            composable(route = NIC700Screen.SETS_COMMON_SET.name) {
                val context: Context = LocalContext.current
                CommonSetScreen()
            }
            // 串口调试页面
            composable(route = NIC700Screen.SETS_COM_SERIAL.name) {
                val context: Context = LocalContext.current
                DemoScreen()
            }
            // WebView测试页面
            composable(route = NIC700Screen.WEBVIEW_TEST.name) {
                val context:Context = LocalContext.current
                WebViewScreen()
            }

        }
    }
}




/**
 * 顶部状态栏
 */
@Composable
fun StatusBar() {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .height(100.dp)
            .background(color = Color(0xFFFF7F00)),
        verticalAlignment = Alignment.CenterVertically
    ) {
        Spacer(modifier = Modifier.width(8.dp))
        Text(
            text = "NIC700--测试平台",
            color = Color.White
        )
        Spacer(modifier = Modifier.weight(1f))
        Icon(
            imageVector = Icons.Default.Star,
            contentDescription = "星星",
            tint = Color.White,
            modifier = Modifier.size(36.dp)
        )
        Spacer(modifier = Modifier.width(8.dp))

    }
}

@Preview(device = Devices.AUTOMOTIVE_1024p,
    widthDp = 2173,
    heightDp = 	1223,
    showBackground = true)
@Composable
fun ScreenPreview() {
    WLWTheme {
        NIC700App()
    }
}